package com.twu.biblioteca;

/**
 * Created by siba on 27/09/14.
 */
public class MovieInformation {

    public static Movie [] libraryMovies;

    public static Movie [] getLibraryMovies(){
        return libraryMovies;
    }

    public static Movie[] fetchLibraryMovies() {

        Movie movies [] = new Movie[3];

        movies[0] = new Movie();
        movies[0].setName("m1");
        movies[0].setDirector("d1");
        movies[0].setYear("2000");
        movies[0].setRating("1");

        movies[1] = new Movie();
        movies[1].setName("m2");
        movies[1].setDirector("d2");
        movies[1].setYear("2002");
        movies[1].setRating("unrated");

        movies[2] = new Movie();
        movies[2].setName("m3");
        movies[2].setDirector("d3");
        movies[2].setYear("2009");
        movies[2].setRating("8");

        return movies;
    }

    public static void toggleMovieCheckedOutInfo(Movie libraryMovie) {
        for (int count = 0; count < libraryMovies.length; count++) {
            if (libraryMovie.getName().equalsIgnoreCase(libraryMovies[count].getName()) &&
                    libraryMovie.getDirector().equalsIgnoreCase(libraryMovies[count].getDirector()) &&
                    libraryMovie.getYear().equalsIgnoreCase(libraryMovies[count].getYear())) {
                libraryMovies[count].setIsCheckedOut(!libraryMovies[count].getIsCheckedOut());
                break;
            }
        }

    }

    public static void init() {
        libraryMovies = fetchLibraryMovies();
    }
}
